package org.dromara.netbar.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.netbar.domain.vo.NetbarSeatMemberRateVo;
import org.dromara.netbar.domain.bo.NetbarSeatMemberRateBo;
import org.dromara.netbar.service.INetbarSeatMemberRateService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 座位-会员费率关联
 *
 * @author Lion Li
 * @date 2025-07-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/netbar/seatMemberRate")
public class NetbarSeatMemberRateController extends BaseController {

    private final INetbarSeatMemberRateService netbarSeatMemberRateService;

    /**
     * 查询座位-会员费率关联列表
     */
    @SaCheckPermission("netbar:seatMemberRate:list")
    @GetMapping("/list")
    public TableDataInfo<NetbarSeatMemberRateVo> list(NetbarSeatMemberRateBo bo, PageQuery pageQuery) {
        return netbarSeatMemberRateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出座位-会员费率关联列表
     */
    @SaCheckPermission("netbar:seatMemberRate:export")
    @Log(title = "座位-会员费率关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NetbarSeatMemberRateBo bo, HttpServletResponse response) {
        List<NetbarSeatMemberRateVo> list = netbarSeatMemberRateService.queryList(bo);
        ExcelUtil.exportExcel(list, "座位-会员费率关联", NetbarSeatMemberRateVo.class, response);
    }

    /**
     * 获取座位-会员费率关联详细信息
     *
     * @param seatMemberRateId 主键
     */
    @SaCheckPermission("netbar:seatMemberRate:query")
    @GetMapping("/{seatMemberRateId}")
    public R<NetbarSeatMemberRateVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long seatMemberRateId) {
        return R.ok(netbarSeatMemberRateService.queryById(seatMemberRateId));
    }

    /**
     * 新增座位-会员费率关联
     */
    @SaCheckPermission("netbar:seatMemberRate:add")
    @Log(title = "座位-会员费率关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NetbarSeatMemberRateBo bo) {
        return toAjax(netbarSeatMemberRateService.insertByBo(bo));
    }

    /**
     * 修改座位-会员费率关联
     */
    @SaCheckPermission("netbar:seatMemberRate:edit")
    @Log(title = "座位-会员费率关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NetbarSeatMemberRateBo bo) {
        return toAjax(netbarSeatMemberRateService.updateByBo(bo));
    }

    /**
     * 删除座位-会员费率关联
     *
     * @param seatMemberRateIds 主键串
     */
    @SaCheckPermission("netbar:seatMemberRate:remove")
    @Log(title = "座位-会员费率关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{seatMemberRateIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] seatMemberRateIds) {
        return toAjax(netbarSeatMemberRateService.deleteWithValidByIds(List.of(seatMemberRateIds), true));
    }
}
